package com.奇技淫巧;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Callback {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<>(new MyThread());
        Thread t1 = new Thread(futureTask,"t1");
        Thread t2 = new Thread(futureTask,"t2");

        t1.start();
        System.out.println(futureTask.get());
        t2.start();
        System.out.println(futureTask.get());
        Thread t3 = new Thread(futureTask,"t3");
        t3.start();
        System.out.println(futureTask.get());
    }


    static class MyThread implements Callable<Integer>{

        @Override
        public Integer call() throws Exception {
            System.out.println(Thread.currentThread().getId());
            System.out.println(Thread.currentThread().getName());
            return 1024;
        }
    }
}
